package cn.janyd.jmall.management.manager.passport;

import cn.janyd.common.core.vo.CommonResult;
import cn.janyd.jmall.management.controller.passport.vo.AdminLoginDTO;
import cn.janyd.jmall.management.controller.passport.vo.PassportTokenRespVo;
import cn.janyd.jmall.management.converter.passport.PassportConverter;
import cn.janyd.jmall.system.rpc.admin.AdminRpcService;
import cn.janyd.jmall.system.rpc.admin.dto.AdminRespDTO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * @author Janyd
 * @since 2020-08-15 17:26
 */
@Service
public class PassportManager {

    @DubboReference(version = "${jmall.dubbo.versions.AdminRpcService}")
    private AdminRpcService adminRpcService;

    public PassportTokenRespVo login(AdminLoginDTO adminLoginDTO) {
        CommonResult<AdminRespDTO> loginResult = adminRpcService.verifyPassword(PassportConverter.INSTANCE.convert(adminLoginDTO));
        loginResult.checkError();

        return new PassportTokenRespVo()
                .setAccessToken("xxx")
                .setRefreshToken("xxx")
                .setExpiresTime(LocalDateTime.now());
    }
}
